﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;
using System.Text;

using CE.User;
using CE.Global;
using CE.Database;
using CE.Mail;

public partial class homeloan_UserMessage : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

        if (Session[General.HLId] != null &&
            Session[General.HLUserName] != null &&
            Session[General.HLEmail] != null &&
            Session[General.HLPhoneNo] != null)
        {
            lblMessageHeader.Text = "Thank you for using CompareXpress Home Loans Comparison tool. ";
            lblMessageBody.Text = "<b>We will forward your enquiry to the respective banks that you've selected and they will get in touch with you shortly.</b>";

            SendEmailToProvider();

            General.ClearAllSession(this.Page, "ALL");
        }
        else
        {
            Response.Redirect("home-loan.aspx");
        }
    }

    private void SendEmailToProvider()
    {
        MyDatabase _db = new MyDatabase();
        DataTable _dtSeletedItem = new DataTable("tblSeletedHLItem");

        string _strHLID = Session[General.HLId].ToString();
        _dtSeletedItem = _db.GetDataTable("Select HLTempID, ProviderCompanyID, PackageName, CXPackageName, ThreeYearInterest, " +
                               "IsLockIn, LockInPeriod FROM tblHLTempResult Where RefHLID = " + _strHLID + " AND IsSelected = 1");

        string _strRefHLID = "CXHL" + General.GetRefNumber(Convert.ToInt64(_strHLID));
        string _strEmailSubject = "Home Loans Selected Packages - (Ref No:" + _strRefHLID + ") from CompareXpress.com";// " - DateTime : " + CE.Global.General.GetUTCDateTime().ToString("dd/MMM/yyyy");

        Uri myUri = new Uri(HttpContext.Current.Request.Url.ToString());

        string domainUrl = "http://" + Request.Url.Host.ToString();
        string imgUrl = domainUrl;
        
        if (_dtSeletedItem != null && _dtSeletedItem.Rows.Count > 0)
        {
            string _maybankSeletedItemRow = string.Empty;
            string _stdcSeletedItemRow = string.Empty;
            string _cimbSeletedItemRow = string.Empty;
            string _rhbSeletedItemRow = string.Empty;

            for (int i = 0; i < _dtSeletedItem.Rows.Count; i++)
            {
                //Standard Charter
                if (_dtSeletedItem.Rows[i]["ProviderCompanyID"].ToString() == "18")
                {
                    //_stdcSeletedItemRow += "<tr><td height=\"45\" style=\"background:#d5d5d5; border-bottom:1px solid #ccc;\">" + _dtSeletedItem.Rows[i]["PackageName"].ToString() + "</td><td height=\"45\" style=\"background:#d5d5d5; border-bottom:1px solid #ccc;\">" + _dtSeletedItem.Rows[i]["CXPackageName"].ToString() + "</td><td align=\"center\" style=\"background:#bfbfbf; color:#313131;\"><strong>S$ " + FormatThousandSeperator(_dtSeletedItem.Rows[i]["ThreeYearInterest"].ToString()) + "</strong></td>";
                    _stdcSeletedItemRow += "<tr><td height=\"45\" style=\"background:#d5d5d5; border-bottom:1px solid #ccc;\">" + _dtSeletedItem.Rows[i]["PackageName"].ToString() + "</td><td align=\"center\" style=\"background:#bfbfbf; color:#313131;\"><strong>S$ " + FormatThousandSeperator(_dtSeletedItem.Rows[i]["ThreeYearInterest"].ToString()) + "</strong></td>";
                    if (_dtSeletedItem.Rows[i]["IsLockIn"].ToString() == "True" || _dtSeletedItem.Rows[i]["IsLockIn"].ToString() == "1")
                    {
                        _stdcSeletedItemRow += "<td align=\"center\" style=\"background:#bfbfbf; color:#fffff;\"><img alt=\"Lock-In Period\" src=\"" + imgUrl + "/images/icon/tick_2.png\" /><br/>" + _dtSeletedItem.Rows[i]["LockInPeriod"].ToString() + " years</td>";
                    }
                    else
                    {
                        _stdcSeletedItemRow += "<td align=\"center\" style=\"background:#bfbfbf; color:#fffff;\"><img alt=\"Lock-In Period\" src=\"" + imgUrl + "/images/icon/x_2.png\" /><br/>No Lock-In</td>";
                    }

                    _stdcSeletedItemRow += "</tr>";
                }

                //RHB
                if (_dtSeletedItem.Rows[i]["ProviderCompanyID"].ToString() == "21")
                {
                    //_rhbSeletedItemRow += "<tr><td height=\"45\" style=\"background:#d5d5d5; border-bottom:1px solid #ccc;\">" + _dtSeletedItem.Rows[i]["PackageName"].ToString() + "</td><td height=\"45\" style=\"background:#d5d5d5; border-bottom:1px solid #ccc;\">" + _dtSeletedItem.Rows[i]["CXPackageName"].ToString() + "</td><td align=\"center\" style=\"background:#bfbfbf; color:#313131;\"><strong>S$ " + FormatThousandSeperator(_dtSeletedItem.Rows[i]["ThreeYearInterest"].ToString()) + "</strong></td>";
                    _rhbSeletedItemRow += "<tr><td height=\"45\" style=\"background:#d5d5d5; border-bottom:1px solid #ccc;\">" + _dtSeletedItem.Rows[i]["PackageName"].ToString() + "</td><td align=\"center\" style=\"background:#bfbfbf; color:#313131;\"><strong>S$ " + FormatThousandSeperator(_dtSeletedItem.Rows[i]["ThreeYearInterest"].ToString()) + "</strong></td>";
                    if (_dtSeletedItem.Rows[i]["IsLockIn"].ToString() == "True" || _dtSeletedItem.Rows[i]["IsLockIn"].ToString() == "1")
                    {
                        _rhbSeletedItemRow += "<td align=\"center\" style=\"background:#bfbfbf; color:#fffff;\"><img alt=\"Lock-In Period\" src=\"" + imgUrl + "/images/icon/tick_2.png\" /><br/>" + _dtSeletedItem.Rows[i]["LockInPeriod"].ToString() + " years</td>";
                    }
                    else
                    {
                        _rhbSeletedItemRow += "<td align=\"center\" style=\"background:#bfbfbf; color:#fffff;\"><img alt=\"Lock-In Period\" src=\"" + imgUrl + "/images/icon/x_2.png\" /><br/>No Lock-In</td>";
                    }

                    _rhbSeletedItemRow += "</tr>";
                }


                //CIMB
                if (_dtSeletedItem.Rows[i]["ProviderCompanyID"].ToString() == "26")
                {
                    //_cimbSeletedItemRow += "<tr><td height=\"45\" style=\"background:#d5d5d5; border-bottom:1px solid #ccc;\">" + _dtSeletedItem.Rows[i]["PackageName"].ToString() + "</td><td height=\"45\" style=\"background:#d5d5d5; border-bottom:1px solid #ccc;\">" + _dtSeletedItem.Rows[i]["CXPackageName"].ToString() + "</td><td align=\"center\" style=\"background:#bfbfbf; color:#313131;\"><strong>S$ " + FormatThousandSeperator(_dtSeletedItem.Rows[i]["ThreeYearInterest"].ToString()) + "</strong></td>";
                    _cimbSeletedItemRow += "<tr><td height=\"45\" style=\"background:#d5d5d5; border-bottom:1px solid #ccc;\">" + _dtSeletedItem.Rows[i]["PackageName"].ToString() + "</td><td align=\"center\" style=\"background:#bfbfbf; color:#313131;\"><strong>S$ " + FormatThousandSeperator(_dtSeletedItem.Rows[i]["ThreeYearInterest"].ToString()) + "</strong></td>";
                    if (_dtSeletedItem.Rows[i]["IsLockIn"].ToString() == "True" || _dtSeletedItem.Rows[i]["IsLockIn"].ToString() == "1")
                    {
                        _cimbSeletedItemRow += "<td align=\"center\" style=\"background:#bfbfbf; color:#fffff;\"><img alt=\"Lock-In Period\" src=\"" + imgUrl + "/images/icon/tick_2.png\" /><br/>" + _dtSeletedItem.Rows[i]["LockInPeriod"].ToString() + " years</td>";
                    }
                    else
                    {
                        _cimbSeletedItemRow += "<td align=\"center\" style=\"background:#bfbfbf; color:#fffff;\"><img alt=\"Lock-In Period\" src=\"" + imgUrl + "/images/icon/x_2.png\" /><br/>No Lock-In</td>";
                    }

                    _cimbSeletedItemRow += "</tr>";
                }

                //MayBank
                if (_dtSeletedItem.Rows[i]["ProviderCompanyID"].ToString() == "28")
                {
                    //_maybankSeletedItemRow += "<tr><td height=\"45\" style=\"background:#d5d5d5; border-bottom:1px solid #ccc;\">" + _dtSeletedItem.Rows[i]["PackageName"].ToString() + "</td><td height=\"45\" style=\"background:#d5d5d5; border-bottom:1px solid #ccc;\">" + _dtSeletedItem.Rows[i]["CXPackageName"].ToString() + "</td><td align=\"center\" style=\"background:#bfbfbf; color:#313131;\"><strong>S$ " + FormatThousandSeperator(_dtSeletedItem.Rows[i]["ThreeYearInterest"].ToString()) + "</strong></td>";
                    _maybankSeletedItemRow += "<tr><td height=\"45\" style=\"background:#d5d5d5; border-bottom:1px solid #ccc;\">" + _dtSeletedItem.Rows[i]["PackageName"].ToString() + "</td><td align=\"center\" style=\"background:#bfbfbf; color:#313131;\"><strong>S$ " + FormatThousandSeperator(_dtSeletedItem.Rows[i]["ThreeYearInterest"].ToString()) + "</strong></td>";
                    if (_dtSeletedItem.Rows[i]["IsLockIn"].ToString() == "True" || _dtSeletedItem.Rows[i]["IsLockIn"].ToString() == "1")
                    {
                        _maybankSeletedItemRow += "<td align=\"center\" style=\"background:#bfbfbf; color:#fffff;\"><img alt=\"Lock-In Period\" src=\"" + imgUrl + "/images/icon/tick_2.png\" /><br/>" + _dtSeletedItem.Rows[i]["LockInPeriod"].ToString() + " years</td>";
                    }
                    else
                    {
                        _maybankSeletedItemRow += "<td align=\"center\" style=\"background:#bfbfbf; color:#fffff;\"><img alt=\"Lock-In Period\" src=\"" + imgUrl + "/images/icon/x_2.png\" /><br/>No Lock-In</td>";
                    }

                    _maybankSeletedItemRow += "</tr>";
                }
            }

            DataTable _dtQuoteDetail = new DataTable("tblQuoteDetail");

            _dtQuoteDetail = _db.GetDataTable("Select HLMortgageType, HLPropertyType, HLAmount, HLLoanTenure, FullName, ContactNo, Email, Info1 FROM tblHLRequest Where Status = 1 And HLId = " + _strHLID);

            if (_dtQuoteDetail != null && _dtQuoteDetail.Rows.Count > 0)
            {
                string _strMortageType = string.Empty;
                string _strPropertyType = string.Empty;
                string _strLoanAmountAndTenure = string.Empty;

                string _strFullName = string.Empty;
                string _strEmail = string.Empty;
                string _strContactNo = string.Empty;
                string _strCurrentBank = string.Empty;

                if (_dtQuoteDetail.Rows[0]["HLMortgageType"].ToString() == "1")
                {
                    _strMortageType = "Refinancing";
                    _strCurrentBank = _dtQuoteDetail.Rows[0]["Info1"].ToString();
                }
                else
                {
                    _strMortageType = "New Loan";
                }

                if (_dtQuoteDetail.Rows[0]["HLPropertyType"].ToString() == "1")
                {
                    _strPropertyType = "HDB";
                }
                else
                {
                    _strPropertyType = "Private";
                }

                _strLoanAmountAndTenure = "S$ " + Convert.ToInt32(_dtQuoteDetail.Rows[0]["HLAmount"].ToString()).ToString("#,000") + " (" + _dtQuoteDetail.Rows[0]["HLLoanTenure"].ToString() + " years) ";

                _strFullName = _dtQuoteDetail.Rows[0]["FullName"].ToString();

                _strEmail = _dtQuoteDetail.Rows[0]["Email"].ToString();

                _strContactNo = _dtQuoteDetail.Rows[0]["ContactNo"].ToString();

                string _strQuoteDetail = "<table width='510' border='0' cellpadding='5' cellspacing='0'>" +
                                        "<tr><td width='204'>Mortgage Type</td><td width='306' align='center' style=\"background:#e5e5e5;\">" + _strMortageType + "</td></tr>";

                if (_strCurrentBank != string.Empty)
                {
                    _strQuoteDetail += "<tr><td width='204'>Current Bank</td><td width='306' align='center' style=\"background:#e5e5e5;\">" + _strCurrentBank + "</td></tr>";
                }

                _strQuoteDetail += "<tr><td>Property Type</td><td align='center' style=\"background:#e5e5e5\">" + _strPropertyType + "</td></tr>" +
                                        "<tr><td style=\"background:#e5e5e5;\">Loan Amount</td><td align=\"center\" style=\"background:#d5d5d5; color:#313131; font-size:14px;\"><strong>" + _strLoanAmountAndTenure + "</strong></td></tr>" +
                                        "<tr><td>Full Name</td><td align='center' style=\"background:#e5e5e5\">" + _strFullName + "</td></tr>" +
                                        "<tr><td>Email</td><td align='center' style=\"background:#e5e5e5\">" + _strEmail + "</td></tr>" +
                                        "<tr><td>Contact No</td><td align='center' style=\"background:#e5e5e5\">" + _strContactNo + "</td></tr></table>";

                //Send Mail Standard Chartered
                if (_stdcSeletedItemRow != string.Empty)
                {
                    string _stdcEmailTo = CE.Configuration.MyConfigurationManager.GetAppSettingValue("STDCHL_TOEmail");
                    string _stdcemailCC = CE.Configuration.MyConfigurationManager.GetAppSettingValue("STDCHL_CCEmail");
                    string _stdcemailBCC = CE.Configuration.MyConfigurationManager.GetAppSettingValue("STDCHL_BCCEmail");
                    SendEmail(_stdcEmailTo, _stdcemailCC, _stdcemailBCC, "Standard Chartered", "(SC) " + _strEmailSubject, _strQuoteDetail, _stdcSeletedItemRow);

                }

                //Send Mail RHB
                if (_rhbSeletedItemRow != string.Empty)
                {
                    string _rhbEmailTo = CE.Configuration.MyConfigurationManager.GetAppSettingValue("RHBHL_TOEmail");
                    string _rhbemailCC = CE.Configuration.MyConfigurationManager.GetAppSettingValue("RHBHL_CCEmail");
                    string _rhbemailBCC = CE.Configuration.MyConfigurationManager.GetAppSettingValue("RHBHL_BCCEmail");
                    SendEmail(_rhbEmailTo, _rhbemailCC, _rhbemailBCC, "RHB", "(RHB) " + _strEmailSubject, _strQuoteDetail, _rhbSeletedItemRow);

                }

                //Send Mail CIMB
                if (_cimbSeletedItemRow != string.Empty)
                {
                    string _cimbEmailTo = CE.Configuration.MyConfigurationManager.GetAppSettingValue("CIMBHL_TOEmail");
                    string _cimbemailCC = CE.Configuration.MyConfigurationManager.GetAppSettingValue("CIMBHL_CCEmail");
                    string _cimbemailBCC = CE.Configuration.MyConfigurationManager.GetAppSettingValue("CIMBHL_BCCEmail");
                    SendEmail(_cimbEmailTo, _cimbemailCC, _cimbemailBCC, "CIMB", "(CIMB) " + _strEmailSubject, _strQuoteDetail, _cimbSeletedItemRow);

                }

                //Send Mail MayBank
                if (_maybankSeletedItemRow != string.Empty)
                {
                    string _mayBankEmailTo = CE.Configuration.MyConfigurationManager.GetAppSettingValue("MayBankHL_TOEmail");
                    string _mayBankemailCC = CE.Configuration.MyConfigurationManager.GetAppSettingValue("MayBankHL_CCEmail");
                    string _mayBankemailBCC = CE.Configuration.MyConfigurationManager.GetAppSettingValue("MayBankHL_BCCEmail");
                    SendEmail(_mayBankEmailTo, _mayBankemailCC, _mayBankemailBCC, "May Bank", "(MAY) " + _strEmailSubject, _strQuoteDetail, _maybankSeletedItemRow);

                }
            }


        }
    }

    private bool SendEmail(string emailTo, string emailCC, string emailBCC, string ProviderName, string emailSubject, string QuoteDetail, string SelectedItemRow)
    {
        bool _retVal = false;

        string _currentDomainUrl = "http://" + HttpContext.Current.Request.Url.Host.ToString();
        string imgLogoUrl = _currentDomainUrl + CE.Configuration.MyConfigurationManager.GetAppSettingValue("LogoPath");


        string _baseUrl = "http://" + Request.Url.Host.ToString();
        StringBuilder strEmailBody = new StringBuilder();
        //strEmailBody.Append("<link rel=\"stylesheet\" type=\"text/css\" href=\"" + _baseUrl + "/css/email.css\"/>");
        strEmailBody.Append("<body class='email_body'>");
        strEmailBody.Append("<style type='text/css'>");
        strEmailBody.Append(".email_body {background:white;margin:0; padding:0; color:#4c4c4c; font-family:Arial, Helvetica, sans-serif; font-size:0.85em;}");
        strEmailBody.Append("a {text-decoration:underline;color:#2c95cc;} ");
        strEmailBody.Append("</style>");

        strEmailBody.Append("<center><table cellspacing='0' cellpadding='0' width='596px'><tr><td>");

        strEmailBody.Append("<tr><td><a href=\"http://www.comparexpress.com/\" target=\"_blank\"><img src=\"" + _baseUrl + "/images/email/header_homeloan.png\" width='596' height=\"187\" alt=\"CompareXpress\" border=\"0\" /></a></td></tr>");

        strEmailBody.Append("<tr><td align='center'><table width='510' border='0' cellpadding='5' cellspacing='0'><tr><td>");
        strEmailBody.Append("<strong>Dear " + ProviderName + ",</strong><br/><br/>");
        strEmailBody.Append("You just received a home loan request from CompareXpress.<br/>Please check details as below.<br/><br/>");
        strEmailBody.Append("</td></tr></table></td></tr>");

        strEmailBody.Append("<tr><td align='center'>" + QuoteDetail);

        strEmailBody.Append("<hr size='1' color='#b8b8b8' width='510'/>");
        strEmailBody.Append("<table width='510' border='0' cellpadding='5' cellspacing='2'>");
        strEmailBody.Append("<th width='50%' height='40' align=\"center\" style=\"background:#c5c5c5;\"><strong>Package</strong></th>");
        //strEmailBody.Append("<th width='30%' height='40' align=\"center\" style=\"background:#c5c5c5;\"><strong>CX Package</strong></th>");
        strEmailBody.Append("<th width='25%' align='center' style=\"background:#c5c5c5;\"><strong>Total Interest(3 yrs)</strong></th>");
        strEmailBody.Append("<th width='25%' align='center' style=\"background:#c5c5c5;\"><strong>Lock-In</strong></th>");

        strEmailBody.Append(SelectedItemRow);

        strEmailBody.Append("</table>");
        strEmailBody.Append("<hr size='1' color='#b8b8b8' width='510'/>");
        strEmailBody.Append("</td></tr>");
        strEmailBody.Append("<tr><td><a href=\"http://www.comparexpress.com/\" target=\"_blank\"><img src=\"" + _baseUrl + "/images/email/footer_quote.png\" alt='CompareXpress - Partners' width=\"596\" height=\"174\" border=\"0\" /></a></td></tr>");
        strEmailBody.Append("</table></center>");
        strEmailBody.Append("</body>");

        if (MyMailManager.SendCRMProviderMessage(emailTo, emailCC, emailBCC, emailSubject, strEmailBody.ToString()))
        {
            _retVal = true;
        }

        return _retVal;
    }

    private string FormatThousandSeperator(string strValue)
    {
        string _retValue = strValue;
        try
        {
            Double _dValue = Convert.ToDouble(strValue);
            Double _dCValue = 1000.00d;
            if (_dValue >= _dCValue)
            {
                _retValue = _dValue.ToString("#,000.00");
            }
            else
            {
                _retValue = _dValue.ToString("#.00");
            }
        }
        catch (Exception Ex)
        {
            throw Ex;
        }


        return _retValue;
    }
    //protected string _header;
    //protected string _body;
    //protected string _headerMsg;
    //protected string _bodyMsg;

    //protected void Page_Load(object sender, EventArgs e)
    //{
    //    if (!IsPostBack)
    //    {
    //        string ProviderId, referencenum, emailadd;
    //        ProviderId = "0"; referencenum = ""; emailadd = "";
    //        if (Request.QueryString["pcid"] != null)
    //        {
    //            ProviderId = Decode(Request.QueryString["pcid"]).ToString();
    //            if (ProviderId == "23")
    //            {
    //                referencenum = Request.QueryString["ref"].ToString();
    //                emailadd = CE.Configuration.MyConfigurationManager.GetAppSettingValue("HSBCTI_UserMessageEmail");

    //                GetMessage(400, "TI", 23200);
    //                _headerMsg = string.Format(_header);
    //                _bodyMsg = string.Format(_body, referencenum, emailadd, emailadd);
    //                lblMessageHeader.Text = _headerMsg;
    //                lblMessageBody.Text = _bodyMsg;

    //                //lblMessageHeader.Text = "Thank you for submitting the application for TravelSurance Quotation";
    //                //lblMessageBody.Text = "HSBC Insurance officer will contact you shortly to finalise the transaction. The quotation reference number is " + referencenum + ". For urgent submission or further assistance, you may contact HSBC Insurance at (65)6225 6111 or email <a href='mailto:" + emailadd + "' target='_blank' >" + emailadd + "</a>.";

    //            }
    //            else if (ProviderId == "29")
    //            {
    //                referencenum = Request.QueryString["ref"].ToString();
    //                emailadd = CE.Configuration.MyConfigurationManager.GetAppSettingValue("LibertyTI_UserMessageEmail");

    //                GetMessage(400, "TI", 29200);
    //                _headerMsg = string.Format(_header, referencenum);
    //                _bodyMsg = string.Format(_body, emailadd, emailadd);
    //                lblMessageHeader.Text = _headerMsg;
    //                lblMessageBody.Text = _bodyMsg;

    //                //lblMessageHeader.Text = "Proposal reference: " + referencenum + "<br/><br/>"
    //                //    + "Thank you. Your completed proposal form is submitted to Liberty Insurance.";

    //                //lblMessageBody.Text = "Liberty will email you the confirmation within 1 working day. <br/><br/>"
    //                //    + "If you have queries, you may contact 6221 8611 or email <a href='mailto:" + emailadd + "' target='_blank' >" + emailadd + "</a>.";


    //            }
    //            else if (ProviderId == "24")
    //            {
    //                referencenum = Request.QueryString["ref"].ToString();
    //                emailadd = CE.Configuration.MyConfigurationManager.GetAppSettingValue("RSATI_UserMessageEmail");

    //                GetMessage(400, "TI", 24200);
    //                _headerMsg = string.Format(_header, referencenum);
    //                _bodyMsg = string.Format(_body, emailadd, emailadd);
    //                lblMessageHeader.Text = _headerMsg;
    //                lblMessageBody.Text = _bodyMsg;

    //                //lblMessageHeader.Text = "Proposal reference: " + referencenum + "<br/><br/>"
    //                //    + "Thank you. Your completed proposal form is submitted to RSA Insurance Group.";

    //                //lblMessageBody.Text = "RSA will email you the confirmation within 1 working day. <br/><br/>"
    //                //    + "If you have queries, you may contact 6423 0888 or email <a href='mailto:" + emailadd + "' target='_blank' >" + emailadd + "</a>.";
    //            }

    //            else if (ProviderId == "34")
    //            {
    //                referencenum = Request.QueryString["ref"].ToString();
    //                emailadd = CE.Configuration.MyConfigurationManager.GetAppSettingValue("ChinaTI_UserMessageEmail");

    //                GetMessage(400, "TI", 34200);
    //                _headerMsg = string.Format(_header, referencenum);
    //                _bodyMsg = string.Format(_body, emailadd, emailadd);
    //                lblMessageHeader.Text = _headerMsg;
    //                lblMessageBody.Text = _bodyMsg;

    //            }
    //            else if (ProviderId == "35")
    //            {
    //                referencenum = Request.QueryString["ref"].ToString();
    //                emailadd = CE.Configuration.MyConfigurationManager.GetAppSettingValue("EQTI_UserMessageEmail");

    //                GetMessage(400, "TI", 35200);
    //                _headerMsg = string.Format(_header, referencenum);
    //                _bodyMsg = string.Format(_body, emailadd, emailadd);
    //                lblMessageHeader.Text = _headerMsg;
    //                lblMessageBody.Text = _bodyMsg;
    //            }
    //            else if (ProviderId == "36")
    //            {
    //                referencenum = Request.QueryString["ref"].ToString();
    //                emailadd = CE.Configuration.MyConfigurationManager.GetAppSettingValue("ACETI_UserMessageEmail");

    //                GetMessage(400, "TI", 36200);
    //                _headerMsg = string.Format(_header, referencenum);
    //                _bodyMsg = string.Format(_body, emailadd, emailadd);
    //                lblMessageHeader.Text = _headerMsg;
    //                lblMessageBody.Text = _bodyMsg;
    //            }

    //        }
    //        else
    //        {
    //            Response.Redirect("~/");
    //            //Response.Redirect("~/Home.aspx");
    //        }
    //        CE.Global.General.ClearAllSession(this.Page, "ALL");
    //    }
    //}

    //private void GetMessage(Int32 UserTypeId, string MessageType, Int32 ErrorCode)
    //{
    //    MessageDB _messagedb = new MessageDB();
    //    DataTable _Message = new DataTable();
    //    _Message = _messagedb.GetMessage(UserTypeId, MessageType, ErrorCode);
    //    if (_Message != null && _Message.Rows.Count > 0)
    //    {
    //        _header = _Message.Rows[0]["Header"].ToString();
    //        _body = _Message.Rows[0]["Body"].ToString();
    //    }
    //    else
    //    {
    //        _header = "CompareXpress";
    //        _body = "No message found!";
    //    }
    //}

    //public string Decode(string sData)
    //{
    //    try
    //    {
    //        System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding();
    //        System.Text.Decoder utf8Decode = encoder.GetDecoder();
    //        byte[] todecode_byte = Convert.FromBase64String(sData);
    //        int charCount = utf8Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length);
    //        char[] decoded_char = new char[charCount];
    //        utf8Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0);
    //        string result = new String(decoded_char);
    //        return result;
    //    }
    //    catch (Exception ex)
    //    {
    //        Response.Redirect("~/");
    //        //Response.Redirect("~/Home.aspx");
    //        string result = "";
    //        return result;
    //    }
    //}
}
